TARGET		:= led.bin
BUILD		:= led

COBJS		+= main.o
COBJS		+= start.o
COBJS		+= uart.o
COBJS		+= irq.o
COBJS		+= key.o



#tools
CROSS_COMPILE	:= arm-linux-
CC				:= $(CROSS_COMPILE)gcc
LD				:= $(CROSS_COMPILE)ld
OBJCOPY			:= $(CROSS_COMPILE)objcopy
OBJDUMP			:= $(CROSS_COMPILE)objdump

#flags
CFLAGS			+= -Wall
CFLAGS			+= -I./inc
LDFLAGS			+= -Tmap.lds
LDFLAGS			+= -Ttext 0xD0020010
#LDFLAGS			+= -Ttext 0xD0024000
#LDFLAGS			+= -Ttext 0x0


#routine
all:$(TARGET)
$(TARGET) : $(BUILD)
	$(OBJCOPY) -O binary $^ $@.TMP
	./mktiny210 $@.TMP $@
$(BUILD) : $(COBJS)
	$(LD) $(LDFLAGS) -o $@ $^


%.o:%.S
	$(CC) $(CFLAGS) -c -o $@ $< -fno-builtin
	
%.o:%.c
	$(CC) $(CFLAGS) -c -o $@ $< -fno-builtin

clean:
	rm -f $(TARGET) $(BUILD) *.o *.TMP